<!--
Copyright (c) 2024 Industrial Shields. All rights reserved

This file is part of node-red-librpiplc.

node-red-librpiplc is free software: you can redistribute
it and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.

node-red-librpiplc is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<script type="text/javascript">
	RED.nodes.registerType("rpiplc-set-config", {
		category: "Industrial Shields",
		color: "#C7E9C0",

		defaults: {
			rpiplc: { value: "", type: "rpiplc-config", required: true},
			name: { value: "" },
		},

		inputs: 1,
		outputs: 1,

		icon: "serial.svg",
		align: "left",
		labelStyle: "node_label",
		label: function() {
			return this.name || "plc set config";
		},

		paletteLabel: function() {
			return "plc set config";
		},
	});
</script>

<script type="text/x-red" data-template-name="rpiplc-set-config">
  	<div class="form-row">
		<label for="node-input-rpiplc"><i class="fa fa-cog"></i> PLC type</label>
		<input type="text" id="node-input-rpiplc" placeholder="PLC type">
	</div>
	<div class="form-row">
		<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
		<input type="text" id="node-input-name" placeholder="Name">
	</div>
</script>

<script type="text/x-red" data-help-name="rpiplc-set-config">
  <p>
    <b>PLC set config</b>
  </p>
  <p>
    This node allows programmers to change the version and model of the PLC being used while
    executing the Node-RED flows.
  </p>
  <p>
    To change these settings, send a message with the attributes <code>msg.version</code>
    and <code>msg.model</code>. Check the following sections for a list of
    available <a href="https://github.com/Industrial-Shields/node-red-librpiplc/tree/new-pins-enum?tab=readme-ov-file#available-plc-versions">versions</a>
    and <a href="https://github.com/Industrial-Shields/node-red-librpiplc/tree/new-pins-enum?tab=readme-ov-file#available-plc-models">models</a>.
    The node will return a payload containing a number indicating whether the library was
    initialized successfully with the new configuration (0 if correctly initialized; otherwise,
    some error occurred).
  </p>
  <p>
    <b>WARNING</b>
  </p>
  <p>
    This node needs to be configured with a custom configuration node, that is, checking
    the <strong>Select through "plc set config" node</strong> box. Otherwise, it will raise an
    exception every time a message is passed to it.
  </p>

</script>
